﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using JtextEpicsInterface;
using jtext_EpicsServer;

//this is a JEServer demo that usa the PCCounter Driver
namespace Jetest2
{
    class Program
    {
        static void Main(string[] args)
        {
            string TDRVPath = AppDomain.CurrentDomain.BaseDirectory.ToString()+"drv\\" ;
            JEpicsServer MyJEServer = new JEpicsServer("TEST:PCCOUNT", -1); //create the JEServer
            MyJEServer.LoadDrivers(TDRVPath);
            Record_prop TRecorProp = new Record_prop();
            //RecordDriverProp TDrvPro = new RecordDriverProp();
            
            JEDevice MyDevice = new JEDevice("TEST4","notype", true,null);
            JEDevice MyDevice2 = new JEDevice("TEST44","notype", true, null);

            //record prop for cpu usage
            TRecorProp.HIGH = 50;
            TRecorProp.HIHI  = 70;
            //the driver property
            TRecorProp.Drv_name = "JEDPCounter";
            TRecorProp.pvName = "TEST:CPU2";
            TRecorProp.Drv_path = "cpu";
            TRecorProp.DataClass = 0;
            TRecorProp.isInput = true;
            TRecorProp.SCANINTERVAL = 2000;
            MyJEServer.AddRecord<double>(TRecorProp);
            MyDevice.addDeviceProperty("cpu",TRecorProp.pvName,"double;input");

            ////record prop for ram usage
            TRecorProp = new Record_prop();
            //TRecorProp = new RecordDriverProp();
            TRecorProp.LOLO = 300;
            TRecorProp.LOW = 500;
            TRecorProp.HIGH = 5000;
            TRecorProp.HIHI = 7000;
            //the driver property
            TRecorProp.Drv_name = "JEDPCounter";
            TRecorProp.Drv_path = "ram";
            TRecorProp.pvName = "TEST:RAM2";
            TRecorProp.isInput = true;
            TRecorProp.SCANINTERVAL =4000;
            TRecorProp.DataClass = 0;
            MyJEServer.AddRecord<double>( TRecorProp);
            MyDevice.addDeviceProperty("ram",TRecorProp.pvName,"double;input");

            ////record prop for ram usage
            TRecorProp = new Record_prop();
            //TRecorProp = new RecordDriverProp();
            TRecorProp.LOLO = 300;
            TRecorProp.LOW = 500;
            TRecorProp.HIGH = 5000;
            TRecorProp.HIHI = 7000;
            //the driver property
            TRecorProp.Drv_name = "nothing";
            TRecorProp.Drv_path = "nothing";
            TRecorProp.pvName = "TEST:Output2";
            TRecorProp.isInput = false;
            TRecorProp.SCANINTERVAL = 4000;
            TRecorProp.DataClass = 0;
            MyJEServer.AddRecord<double>(TRecorProp);
            
            MyDevice.addDeviceProperty("OutTest", TRecorProp.pvName, CommonConst.DT_DOUBLE+";"+CommonConst.DR_OUTPUT);



            //array test
            TRecorProp = new Record_prop();
            TRecorProp.Drv_name = "nothing";
            TRecorProp.Drv_path = "nothing";
            TRecorProp.pvName = "TEST:ARRAY";
            TRecorProp.isInput = true;
            TRecorProp.DataClass = 1;
            TRecorProp.ArrayLen = 10;
            MyJEServer.AddRecord<sbyte>(TRecorProp);
            MyDevice2.addDeviceProperty("array", TRecorProp.pvName, "SByteArray;Output");
         
            MyJEServer.StartServer();
            MyDevice2.PublishDevice();
            MyDevice.PublishDevice();
            
            while (true)
            {
                Thread.Sleep(1000);
                //MyJEServer.BenchFlush();
            }

            
        }
    }
}
